home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / demos / OpenGL / space / texture.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  4KB  |  130 lines

  1. /*
  2.  * Copyright (C) 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include "space.h"
  18.  
  19. extern t_stopwatch Counter ;
  20.  
  21. /**********************************************************************
  22. *  spTevDef()  -
  23. **********************************************************************/
  24. void spTevDef(void)
  25. {
  26. #ifdef SP_IRIS_GL
  27.    flot32 tevps[4];
  28.  
  29.    tevps[0] = TV_NULL;
  30.    tevdef(1,0,tevps);
  31. #endif
  32.  
  33. #ifdef SP_OPEN_GL
  34.    glTexEnvf(GL_TEXTURE_ENV_MODE,GL_TEXTURE_ENV_MODE,GL_MODULATE);
  35. #endif
  36. }
  37.  
  38. /**********************************************************************
  39. *  spTexDef()  -
  40. **********************************************************************/
  41. uint32 spTexDef(uint32 comp,uint32 dx,uint32 dy,void *arr,uint32 flag)
  42. {
  43.    static uint32 texid = 1;
  44.  
  45. #ifdef SP_IRIS_GL
  46.    flot32 texps[8];
  47.  
  48.    texps[0] = TX_MAGFILTER ;
  49.    texps[1] = TX_BILINEAR ;
  50.    texps[2] = TX_MINFILTER ;
  51.    texps[3] = (flag) ? TX_MIPMAP_TRILINEAR : TX_BILINEAR ;
  52.    texps[4] = TX_WRAP ;
  53.    texps[5] = TX_REPEAT ;
  54.    texps[6] = TX_NULL ;
  55.  
  56.    texdef2d(texid,comp,dx,dy,arr,0,texps);
  57.    return(texid++);
  58. #endif
  59.  
  60. #ifdef SP_OPEN_GL
  61.    uint32 format,i,*lptr,r,g,b,a;
  62.    uint16 *sptr;
  63.  
  64.    texid = glGenLists(1);
  65.    glNewList(texid,GL_COMPILE) ;
  66.  
  67.    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  68.    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  69.    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
  70.    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
  71.  
  72.    switch (comp) {
  73.       case 1 : format = GL_LUMINANCE;
  74.                break;
  75.  
  76.       case 2 : format = GL_LUMINANCE_ALPHA;
  77.                for (sptr=arr,i=dx*dy; i>0; sptr++,i--) {
  78.                  r = (*sptr     ) & 0xff;
  79.                  a = (*sptr >> 8) & 0xff;
  80.                  *sptr = (r<<8) | a; 
  81.                  }
  82.                break;
  83.  
  84.       case 4 : format = GL_RGBA;
  85.                for (lptr=arr,i=dx*dy; i>0; lptr++,i--) {
  86.                  r = (*lptr      ) & 0xff;
  87.                  g = (*lptr >>  8) & 0xff;
  88.                  b = (*lptr >> 16) & 0xff;
  89.                  a = (*lptr >> 24) & 0xff;
  90.                  *lptr = (r<<24) | (g<<16) | (b<<8) | a; 
  91.                  }
  92.                break;
  93.       }
  94.    glTexImage2D(GL_TEXTURE_2D,0,comp,dx,dy,0,format,GL_UNSIGNED_BYTE,arr);
  95.  
  96.    glEndList() ;
  97.    return(texid);
  98. #endif
  99. }
  100.  
  101. /**********************************************************************
  102. *  spFlipTex()  -
  103. **********************************************************************/
  104. void spFlipTex(uint32 flag,uint32 obj)
  105.  
  106. {
  107.    if (!(Counter.flags & TEXTR_FLAG))
  108.      return;
  109.  
  110. #ifdef SP_IRIS_GL
  111.    if (flag) {
  112.      texbind(0,obj);
  113.      tevbind(0,1);
  114.      }
  115.    else {
  116.      texbind(0,0);
  117.      tevbind(0,0);
  118.      }
  119. #endif
  120.  
  121. #ifdef SP_OPEN_GL
  122.    if (flag) {
  123.      glEnable(GL_TEXTURE_2D);
  124.      glCallList(obj) ;
  125.      }
  126.    else glDisable(GL_TEXTURE_2D);
  127. #endif
  128. }
  129.  
  130.